package net.mihome.app.bean;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * Created by ZHAO on 2015/1/31 0031.
 * 本bean是用来承载系统消息的。比如别人评论了你的大字报，系统会发消息给你
 */
public class Letter {
    public Integer id;
    private Integer sendUid;
    private String sendName;
    private Integer toUid;
    private Integer bigpaperId;
    private String createAt;
    private String avatar;
    private String updateAt;
    private String msg;
    private User user;
    private Tweet tweet;
    private Tweet comment;

    public static Letter parse(Map map){
        if(map!=null){
            Letter letter=new Letter();
            letter.setCreateAt((String) map.get("create_at"));
            letter.setUpdateAt((String) map.get("update_at"));
            letter.setAvatar((String) map.get("avatar"));
            letter.setMsg((String) map.get("msg"));

            Double idDouble= (Double) map.get("id");
            letter.setId(idDouble.intValue());

            Double sendUidDouble= (Double) map.get("send_uid");
            letter.setSendUid(sendUidDouble.intValue());

            letter.setSendName((String) map.get("send_uname"));

            Double toUidDouble= (Double) map.get("to_uid");
            letter.setToUid(toUidDouble.intValue());

            Double bigpaperIdDouble= (Double) map.get("bigpaper_id");
            letter.setBigpaperId(bigpaperIdDouble.intValue());
            //
            if(map.get("send_user")!=null){
                letter.setUser(User.parse((Map) map.get("send_user")));
            }
            if(map.get("bigpaper")!=null){
                letter.setTweet(Tweet.parse((Map) map.get("bigpaper")));
            }
            if(map.get("comment")!=null){
                letter.setComment(Tweet.parse((Map) map.get("comment")));
            }
            return letter;
        }else{
            return null;
        }
    }

    public static List<Letter> parseList(List<Map> maps){
        if(maps!=null&&!maps.isEmpty()){
            List<Letter> letters=new ArrayList<>();
            Iterator<Map> iterator=maps.iterator();
            while(iterator.hasNext()){
                Map map=iterator.next();
                Letter letter=parse(map);
                letters.add(letter);
            }
            return letters;
        }else{
            return null;
        }
    }
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getSendUid() {
        return sendUid;
    }

    public void setSendUid(Integer sendUid) {
        this.sendUid = sendUid;
    }

    public String getSendName() {
        return sendName;
    }

    public void setSendName(String sendName) {
        this.sendName = sendName;
    }

    public Integer getToUid() {
        return toUid;
    }

    public void setToUid(Integer toUid) {
        this.toUid = toUid;
    }

    public Integer getBigpaperId() {
        return bigpaperId;
    }

    public void setBigpaperId(Integer bigpaperId) {
        this.bigpaperId = bigpaperId;
    }

    public String getCreateAt() {
        return createAt;
    }

    public void setCreateAt(String createAt) {
        this.createAt = createAt;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getUpdateAt() {
        return updateAt;
    }

    public void setUpdateAt(String updateAt) {
        this.updateAt = updateAt;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Tweet getTweet() {
        return tweet;
    }

    public void setTweet(Tweet tweet) {
        this.tweet = tweet;
    }

    public Tweet getComment() {
        return comment;
    }

    public void setComment(Tweet comment) {
        this.comment = comment;
    }
}
